package com.lovemanai.listener;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;

import com.lovemanai.event.EmailEvent;

public class EmailNotifier implements ApplicationListener<ApplicationEvent>{

	//该方法会在容器发生事件时自动调用
	@Override
	public void onApplicationEvent(ApplicationEvent event) {
		
		//只对EmailEvent做处理
		if(event instanceof EmailEvent) {
			EmailEvent emailEvent = (EmailEvent) event;
			
			System.out.println("接收地址：" + emailEvent.getAddress());
			System.out.println("邮件正文：" + emailEvent.getText());
		} else {
			System.out.println("其他事件：" + event);
		}
		
	}
	
	
}
